package th.retrofit.lib;

public class Solution75 {

    public void sortColors(int[] nums) {
        sortColors(nums, 0, nums.length - 1);
    }

    private void sortColors(int[] nums, int left, int right) {
        if (left >= right) return;
        int i = left, j = right;
        int target = nums[i];
        while (i < j) {
            while (i < j && nums[j] > target){
                j--;
            }
            nums[i] = nums[j];
            while (i < j && nums[i] <= target) {
                i++;
            }
            nums[j] = nums[i];
        }
        nums[i] = target;
        sortColors(nums, left, i - 1);
        sortColors(nums, i + 1, right);
    }

    public static void main(String[] args) {
        int[] colors = new int[]{2,0,1};
        new Solution75().sortColors(colors);
        for (int i = 0; i < colors.length; i++) {
            System.out.print(colors[i]);
            System.out.print(",");
        }
        System.out.println();
    }
}
